/**
 * 
 */
package hu.myai.gui.widgets.model;

/**
 * @author Zsolt Safrany (u203697)
 * 
 */
public class ScalarDecorator implements IScalar {

	private IScalar scalar;

	public ScalarDecorator(IScalar scalar) {
		this.scalar = scalar;
	}

	@Override
	public void addScalarListener(IScalarListener listener) {
		scalar.addScalarListener(listener);
	}

	@Override
	public int getDepth() {
		return scalar.getDepth();
	}

	@Override
	public double getMax() {
		return scalar.getMax();
	}

	@Override
	public double getMin() {
		return scalar.getMin();
	}

	@Override
	public double getValue(int time) {
		return scalar.getValue(time);
	}

	@Override
	public void removeScalarListener(IScalarListener listener) {
		scalar.removeScalarListener(listener);
	}

	@Override
	public void setDepth(int depth) {
		scalar.setDepth(depth);
	}

	@Override
	public void setValue(double value, int color, int style) {
		scalar.setValue(value, color, style);
	}

	public double getAverageValue(int time) {
		double avg = 0;
		time = Math.max(Math.min(time, scalar.getDepth() - 1), 0);

		for (int t = 0; t < time; t++) {
			avg += scalar.getValue(t);
		}
		avg /= time;
		return avg;
	}

	public int getColor(int time) {
		return scalar.getColor(time);
	}

	public int getStyle(int time) {
		return scalar.getStyle(time);
	}

}
